<?php
include_once('./db.conf');
session_start();
// Connects to your Database 
$connection=mysqli_connect(DBHOST, DBUSER, DBPASS,DBDBNAME);
if(isset($_COOKIE['CompanyCookie'])){
//get the company information
	$query1="call getCompany($_SESSION[comID])";
	$check1=mysqli_query($connection,$query1);
	$row= mysqli_fetch_assoc($check1);
//these two lines added because mysql doesnt allow to run the commands below and I dont know why. I had to close and reestablish the connection
mysqli_close($connection);
$connection=mysqli_connect(DBHOST, DBUSER, DBPASS,DBDBNAME);
//if update is submitted
if(isset($_POST['submit'])){
	//check the fields to be updated
	if($_POST['data']=="")//if data field is empty 
		$data=$row['data'];//data is the same as the one in database
	else
		$data=$_POST['data'];
	//check password if typed correct
	if($_POST['pass1']==$_POST['pass2']){
		if($_POST['pass1']=="")
			$pass=$row['passwd'];
		else
			$pass=$_POST['pass1'];
	}
	else
		die('You Typed Wrong Password. Please Check Again...');
	//update the company information
	$query2="call updateCompany($_SESSION[comID],'$row[name]','$data','$pass')";
	if(!$check2=mysqli_query($connection,$query2))
		//echo mysqli_error($connection);
		//printf("Something Went Wrong");
;
	else
		header("Location: index.php");
}
else
{

?> 
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>Update The Data</h1></td></tr>
<tr><td><h2><?php echo strtoupper($row['name'])?>:</h2></td><td>
</td></tr>
<tr><td>IMPORTANT : IF YOU DO NOT WANT TO CHANGE THE FIELD, LEAVE IT BLANK</tr></td>
<tr><td>Data :</td><td>
<input type="text" name="data" maxlength="30">
</td></tr>
<tr><td>Password :</td><td>
<input type="text" name="pass1" maxlength="30">
</td></tr>
<tr><td>Password (Type Again) :</td><td>
<input type="text" name="pass2" maxlength="30">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="OK">
</td></tr>
<?php
}
mysqli_close($connection);
}
else
	die('Session Expired Pleas Login....');
?>